#ifndef ONESTEPONEPASSDBOPERATIONMODEL_H_JM_20130219
#define ONESTEPONEPASSDBOPERATIONMODEL_H_JM_20130219

#include "../generators/ModelGenerator.h"
#include "../generators/Slices.h"
#include "../boxes/DefaultGroupDefinitions.h"
#include "../boxes/DbOperationVersion.h"

#include "DataInputModelPartGenerator.h"
#include "DataOutputModelPartGenerator.h"

namespace jm4bbx {

	class  OneStepOnePassDbOperationModel : public ModelGenerator {
	public:
		OneStepOnePassDbOperationModel(
			const int N, // parallelism level
			const std::string& inputBoxName,
			const InputBoxConfiguration& inpBoxConf,
			const std::string& actionBoxName,
			const std::string& outputBoxName,
			const std::string& outputForm,
			const std::string& typeName) {



				/// Input
				DataInputModelPartGenerator inGen;
				InputBoxConfiguration confs[1] = {inpBoxConf};
				inGen.addBoxes(this, inputBoxName, confs, 1, N, true, true);
				///

				BoxDescriptorPtr action = addBox(actionBoxName, 
					genBoxParam("signal_out", 1), N);

				/// Output
				DataOutputModelPartGenerator oGen;
				oGen.addBoxes(this, outputBoxName, outputForm, N);

				//--------------------------------------------------------------
				//--------------------------------------------------------------
				//-------------------------------------------------------------- 

				inGen.addSlices(this, typeName);


				addSlice(new ForkSlice(inGen.getForkDataBox(0)->getBoxId(), 
					action->getBoxIds(), N, D_O, D_I, genTypes(typeName, 1)));


				addSlice(new MergeSlice(action->getBoxIds(), 
					oGen.getTimerReportBox()->getBoxId(), N, S_O, S_I));

				addSlice(new ParallelSlice(action->getBoxIds(), 
					oGen.getOutputBoxes()->getBoxIds(), N, D_O, D_I, 
					genTypes("BinaryOperationResultIndex", 1)));	// Index do tabulky/stlpca

				oGen.addSlices(this);
		}

	};

} // namespace jm4bbx


#endif
